/*
 * Copyright (c) zhg2yqq.com Corp.
 * All Rights Reserved.
 */
package com.zhg2yqq.wheels.mvc;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.zhg2yqq.wheels.cache.service.ICacheService;
import com.zhg2yqq.wheels.mvc.plugin.XssEscapeArgumentAspect;
import com.zhg2yqq.wheels.mvc.protection.DefaultPreventResubmitService;
import com.zhg2yqq.wheels.mvc.protection.IPreventResubmitService;
import com.zhg2yqq.wheels.mvc.protection.PreventResubmitAspect;

/**
 * @author zhg2yqq, 2023年1月6日
 * @version zhg2yqq v1.0
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {

//    @Override
//    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//        converters.removeIf(e -> e.getClass().isAssignableFrom(StringHttpMessageConverter.class));
//    }

    @Bean
    public XssEscapeArgumentAspect xssEscapeArgumentAspect() {
        return new XssEscapeArgumentAspect();
    }

    @Bean
    @ConditionalOnMissingBean(IPreventResubmitService.class)
    public IPreventResubmitService preventResubmitService(ICacheService cacheService) {
        return new DefaultPreventResubmitService(cacheService);
    }

    @Bean
    public PreventResubmitAspect preventResubmitAspect(IPreventResubmitService preventResubmitService) {
        return new PreventResubmitAspect(preventResubmitService);
    }
}
